#pragma once

#include"Protocol.hpp"
#include<iostream>

class Cal
{
public:
    Response Excute( Request& req)//对传过来的req进行计算任务
    {
        Response resp;

        switch(req.Oper())//获取运算符
        {
            case '+':
                resp.SetResult(req.X() + req.Y());
                break;
            case '-':
                resp.SetResult(req.X() - req.Y());
                break;
            case '*':
                resp.SetResult(req.X() * req.Y());
                break;
            case '/':
                {
                    if(req.Y() == 0)
                    {
                        resp.SetCode(1); // 异常值,直接让code设置为1，说明是除零错误
                        break;
                    }
                    else
                    {
                        resp.SetResult(req.X() / req.Y());
                    }
                }
                break;
            case '%':
            {
                if(req.Y() == 0)
                {
                    resp.SetCode(2); // 异常值,直接让code设置为2，说明是模零错误
                    break;
                }
                else
                {
                    resp.SetResult(req.X() % req.Y());
                }
            }
                break;
            default:
                resp.SetCode(3); // 异常值,直接让code设置为3，说明是非法运算符
                break;
        }
        return resp;
    }
private:

};